package class_code.class_2_单链表;


import node.SeqNode;

public class LinkList<T> {

    SeqNode<T> head = new SeqNode<>();
    SeqNode<T> tail = this.head;

    void append(SeqNode<T> data) {
        this.tail.setNext(data);
        this.tail = tail.getNext();
    }

    void show() {
        SeqNode<T> current = this.head.getNext();
        while (current != null) {
            System.out.print(current.getData() + " ");
            current = current.getNext();
        }
        System.out.println();
    }

    int getLength() {
        SeqNode<T> tmp = this.head;
        int length = 0;
        while (null != tmp && tmp.getNext() != null) {
            length += 1;
            tmp = tmp.getNext();
        }

        return length;
    }

    public static void main(String[] args) {
        LinkList<Integer> linkList = new LinkList<>();

        for (int i = 1; i < 11; i++) {
            linkList.append(new SeqNode<>(i));
        }

        linkList.show();
        System.out.println(linkList.getLength());

    }
}